//
//  TopBtnView.m
//  quxiangtao
//
//  Created by E人一铺 on 2019/2/22.
//  Copyright © 2019年 shanhaijin. All rights reserved.
//

#import "TopBtnView.h"
#import "HomeViewController.h"

@interface TopBtnView ()

@property (weak, nonatomic) IBOutlet UIView *btn1;
@property (weak, nonatomic) IBOutlet UIView *btn2;
@property (weak, nonatomic) IBOutlet UIView *btn3;
@property (weak, nonatomic) IBOutlet UIView *btn4;



@end

@implementation TopBtnView

- (void)awakeFromNib {
    
    [super awakeFromNib];
    
    [self addClickAction];
    
}

- (void)addClickAction {
    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(btnClick:)];
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(btnClick:)];
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(btnClick:)];
    UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(btnClick:)];
    
    
    [self.btn1 addGestureRecognizer:tap1];
    [self.btn2 addGestureRecognizer:tap2];
    [self.btn3 addGestureRecognizer:tap3];
    [self.btn4 addGestureRecognizer:tap4];
    
    
}
- (void) btnClick:(UIGestureRecognizer *)gesture {
    
    NSLog(@"ddddd");
    UIView *v = gesture.view;
    HomeViewController *vc = [[HomeViewController alloc] init];
    switch (v.tag) {
        case 1000:
        {
            
            vc.selectIndex = 0;
            BaseTabbarViewController *Vc = [BaseTabbarViewController sharedMainTabBarVC];
            Vc.selectedIndex = 1;
            UIWindow *keywindow = [[UIApplication sharedApplication].windows firstObject];
            keywindow.rootViewController = Vc;
            [keywindow makeKeyAndVisible];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"NSNotificationTopClick" object:@{@"tag" : [NSString stringWithFormat:@"%zd", v.tag]}];
            
            return;
        }
            
            
            
            break;
            
        case 1001:
            vc.selectIndex = 1;
            vc.title = @"淘宝";
            [self.parentVc.navigationController pushViewController:vc animated:YES];
            break;
            
        case 1002:
            vc.selectIndex = 2;
            vc.title = @"天猫";
            [self.parentVc.navigationController pushViewController:vc animated:YES];
            break;
            
        case 1003:
        {
            vc.selectIndex = 3;
            vc.title = @"京东";
            /*
            UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"提示" message:@"功能待上架" preferredStyle:UIAlertControllerStyleAlert];
            //默认只有标题 没有操作的按钮:添加操作的按钮 UIAlertAction
            
            UIAlertAction *cancelBtn = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                NSLog(@"取消");
            }];
            //添加确定
            UIAlertAction *sureBtn = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull   action) {
                NSLog(@"确定");
            }];
            //设置`确定`按钮的颜色
            [sureBtn setValue:[UIColor redColor] forKey:@"titleTextColor"];
            //将action添加到控制器
            [alertVc addAction:cancelBtn];
            [alertVc addAction :sureBtn];
            //展示
            [[self viewController] presentViewController:alertVc animated:YES completion:nil];
            */
            [self.parentVc.navigationController pushViewController:vc animated:YES];
            break;
        }
        default:
            break;
    }
    
}
- (UIViewController *)viewController {
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder *nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)nextResponder;
        }
    }
    return nil;
}

@end
